// ------------------------防抖---------------------------
var debounce = (fn, ...args) => {
  let timeout = null; // 创建一个标记用来存放定时器的返回值
  return function () {
    // console.log(timeout)
    console.log(this);
    clearTimeout(timeout); // 保证用户输入完之后只有一个setTimeout
    timeout = setTimeout(() => {
      fn.call(this, arguments, args);
    }, 500);
  };
}

function sayHi(e, args) {
  console.log(this, e, args);
  console.log('防抖成功');
}
var inp = document.getElementById('inp');
inp.addEventListener('input', debounce(sayHi)); // 防抖
// ------------------------防抖---------------------------

// ------------------------节流---------------------------
function reduce(fn, wait = 500) {
  let on = true
  return function () {
    if (!on) return false
    on = false
    fn.apply(this, arguments)
    setTimeout(() => {
      on = true
    }, wait)
  }
}

function size(e) {
  console.log(e.target.innerHeight)
}
window.onresize = reduce(size);
// window.addEventListener('resize',size);
// ------------------------节流---------------------------